/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.sys.entity;

import java.util.Date;
import java.util.List;

import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;

import com.jeesite.common.collect.ListUtils;
import com.jeesite.common.entity.BaseEntity;
import com.jeesite.common.entity.DataEntity;
import com.jeesite.common.lang.StringUtils;
import com.jeesite.common.mybatis.annotation.Column;
import com.jeesite.common.mybatis.annotation.JoinTable;
import com.jeesite.common.mybatis.annotation.JoinTable.Type;
import com.jeesite.common.mybatis.annotation.Table;
import com.jeesite.common.mybatis.mapper.query.QueryType;

/**
 * 员工管理Entity
 * @author ThinkGem
 * @version 2017-03-25
 */
@Table(name="${_prefix}sys_employee", alias="a", columns={
		@Column(includeEntity=BaseEntity.class),
		@Column(includeEntity=DataEntity.class),
		@Column(name="emp_code", 	attrName="empCode", 			label="员工编码", isPK=true),
		@Column(name="emp_name", 	attrName="empName", 			label="员工姓名", queryType=QueryType.LIKE),
		@Column(name="emp_name_en", attrName="empNameEn", 			label="英文名", queryType=QueryType.LIKE),
		@Column(name="office_code", attrName="office.officeCode", 	label="机构编码", isQuery=false),
		@Column(name="office_name", attrName="office.officeName", 	label="机构名称", isQuery=false),
		@Column(name="company_code", attrName="company.companyCode", label="公司编码", isQuery=false),
		@Column(name="company_name", attrName="company.companyName", label="公司名称", isQuery=false),
		@Column(name="card_type", attrName="cardType", label="证件类型", isQuery=false),
		@Column(name="card_no", attrName="cardNo", label="证件号码", isQuery=false),
		@Column(name="emp_no", attrName="empNo", label="工号", isQuery=false),
		@Column(name="birthday", attrName="birthday", label="出生日期", isQuery=false),
		@Column(name="education", attrName="education", label="教育程度", isQuery=false),
		@Column(name="nation", attrName="nation", label="民族", isQuery=false),
		@Column(name="major", attrName="major", label="专业", isQuery=false),
		@Column(name="rank", attrName="rank", label="职称", isQuery=false),
		@Column(name="join_time", attrName="joinTime", label="入职时间", isQuery=false),
		@Column(name="quit_time", attrName="quitTime", label="离职时间", isQuery=false),
		@Column(name="expire_time", attrName="expireTime", label="到期时间", isQuery=false),
		@Column(name="is_sign", attrName="isSign", label="是否签约", isQuery=false),
		@Column(name="card_address", attrName="cardAddress", label="证件地址", isQuery=false),
		@Column(name="address", attrName="address", label="居住地址", isQuery=false),
		@Column(name="contact", attrName="contact", label="紧急联系人", isQuery=false),
		@Column(name="contact_tel", attrName="contactTel", label="联系方式", isQuery=false),
		@Column(name="contact_rel", attrName="contactRel", label="关系", isQuery=false),
		@Column(name="certificate", attrName="certificate", label="经纪人资格证号", isQuery=false),
		@Column(name="tel", attrName="tel", label="电话号码", isQuery=false),
		@Column(name="ts_tel", attrName="tsTel", label="投诉电话", isQuery=false),

	}, joinTable={
		@JoinTable(type=Type.LEFT_JOIN, entity=Office.class, alias="o", 
			on="o.office_code = a.office_code",
			columns={@Column(includeEntity=Office.class)}),
		@JoinTable(type=Type.LEFT_JOIN, entity=Company.class, alias="c", 
			on="c.company_code = a.company_code",
			columns={@Column(includeEntity=Company.class)}),
		@JoinTable(type=Type.LEFT_JOIN, entity=Area.class, alias="ar",
			on="ar.area_code = c.area_code", attrName="company.area",
			columns={
				@Column(name="area_name", label="区域名称"),
				@Column(name="area_type", label="区域类型"),
		}),
	}, orderBy="a.update_date DESC"
)
public class Employee extends DataEntity<Employee> {
	
	private static final long serialVersionUID = 1L;
	private String empCode;		// 员工编码
	private String empName;		// 员工姓名
	private String empNameEn;	// 员工英文名
	private Office office;		// 机构编码
	private Company company;	// 公司编码
	
	private String postCode;	// 根据职位查询
	private String cardType;
	private String cardNo;
	private String empNo;
	private String birthday;
	private String education;
	private String nation;
	private String major;
	private String rank;
	private Date joinTime;
	private Date quitTime;
	private Date expireTime;
	private String isSign;
	private String cardAddress;
	private String address;
	private String contact;
	private String contactTel;
	private String contactRel;
	private String certificate;
	private String tel;
	private String tsTel;


	public String getTel() {
		return tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

	public String getTsTel() {
		return tsTel;
	}

	public void setTsTel(String tsTel) {
		this.tsTel = tsTel;
	}


//	@Column(name="real_name", attrName="contactTel", label="实际姓名", isQuery=false),
//	@Column(name="brokers_qualification_certificate", attrName="brokersQualificationCertificate", label="经纪人资格证号", isQuery=false),
//	@Column(name="tel", attrName="tel", label="电话号码", isQuery=false),
//	@Column(name="ts_tel", attrName="tsTel", label="投诉电话", isQuery=false),


	private List<EmployeePost> employeePostList = ListUtils.newArrayList(); // 关联岗位信息
	
	public Employee() {
		this(null);
	}

	public Employee(String id){
		super(id);
	}
	
	public String getEmpCode() {
		return empCode;
	}

	public void setEmpCode(String empCode) {
		this.empCode = empCode;
	}
	
	@Length(min=0, max=100, message="名称长度不能超过 100 个字符")
	public String getEmpName() {
		return empName;
	}

	public void setEmpName(String empName) {
		this.empName = empName;
	}
	
	@Length(min=0, max=100, message="英文名长度不能超过 100 个字符")
	public String getEmpNameEn() {
		return empNameEn;
	}

	public void setEmpNameEn(String empNameEn) {
		this.empNameEn = empNameEn;
	}

	@NotNull(message="归属机构不能为空")
	public Office getOffice() {
		if (office == null){
			office = new Office();
		}
		return office;
	}
	@NotNull(message="归属公司不能为空")
	public Company getCompany() {
		if (company == null){
			company = new Company();
		}
		return company;

	}
	public void setOffice(Office office) {
		this.office = office;
	}



	public void setCompany(Company company) {
		this.company = company;
	}

	public String getCardType() {
		return cardType;
	}

	public void setCardType(String cardType) {
		this.cardType = cardType;
	}

	public String getCardNo() {
		return cardNo;
	}

	public void setCardNo(String cardNo) {
		this.cardNo = cardNo;
	}

	public String getEmpNo() {
		return empNo;
	}

	public void setEmpNo(String empNo) {
		this.empNo = empNo;
	}

	public String getBirthday() {
		return birthday;
	}

	public void setBirthday(String birthday) {
		this.birthday = birthday;
	}

	public String getEducation() {
		return education;
	}

	public void setEducation(String education) {
		this.education = education;
	}

	public String getNation() {
		return nation;
	}

	public void setNation(String nation) {
		this.nation = nation;
	}

	public String getMajor() {
		return major;
	}

	public void setMajor(String major) {
		this.major = major;
	}

	public String getRank() {
		return rank;
	}

	public void setRank(String rank) {
		this.rank = rank;
	}

	public Date getJoinTime() {
		return joinTime;
	}

	public void setJoinTime(Date joinTime) {
		this.joinTime = joinTime;
	}

	public Date getQuitTime() {
		return quitTime;
	}

	public void setQuitTime(Date quitTime) {
		this.quitTime = quitTime;
	}

	public Date getExpireTime() {
		return expireTime;
	}

	public void setExpireTime(Date expireTime) {
		this.expireTime = expireTime;
	}

	public String getIsSign() {
		return isSign;
	}

	public void setIsSign(String isSign) {
		this.isSign = isSign;
	}

	public String getCardAddress() {
		return cardAddress;
	}

	public void setCardAddress(String cardAddress) {
		this.cardAddress = cardAddress;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getContact() {
		return contact;
	}

	public void setContact(String contact) {
		this.contact = contact;
	}

	public String getContactTel() {
		return contactTel;
	}

	public void setContactTel(String contactTel) {
		this.contactTel = contactTel;
	}

	public String getContactRel() {
		return contactRel;
	}

	public void setContactRel(String contactRel) {
		this.contactRel = contactRel;
	}

	public String getCertificate() {
		return certificate;
	}

	public void setCertificate(String certificate) {
		this.certificate = certificate;
	}

	public String getPostCode() {
		return postCode;
	}

	public void setPostCode(String postCode) {
		this.postCode = postCode;
	}

	public List<EmployeePost> getEmployeePostList() {
		return employeePostList;
	}
	
	public void setEmployeePostList(List<EmployeePost> employeePostList) {
		this.employeePostList = employeePostList;
	}

	public String[] getEmployeePosts() {
		List<String> list = ListUtils.extractToList(employeePostList, "postCode");
		return list.toArray(new String[list.size()]);
	}

	public void setEmployeePosts(String[] employeePosts) {
		for (String val : employeePosts){
			if (StringUtils.isNotBlank(val)){
				EmployeePost e = new EmployeePost();
				e.setPostCode(val);
				this.employeePostList.add(e);
			}
		}
	}
	
}